<template>
  <div class="app-container">
    <!-- header -->
    <mt-header fixed title="小黑的第一个app">
      <a @click="goBack()" slot="left" v-show="flag">
        <mt-button icon="back">返回</mt-button>
      </a>
    </mt-header>
    <!-- main -->
    <transition name="container">
      <router-view></router-view>
    </transition>
    <!-- tabbar -->
    <van-tabbar v-model="active">
      <van-tabbar-item route to="/home" icon="home-o">首页</van-tabbar-item>
      <van-tabbar-item route to="/member" icon="search">会员</van-tabbar-item>
      <van-tabbar-item
        route
        to="/shopcar"
        icon="cart-o"
        id="badeg"
        :info="$store.getters.getAllCount"
      >购物车</van-tabbar-item>
      <van-tabbar-item route to="/search" icon="search">搜索</van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
export default {
  data() {
    return {
      active: 2,
      flag: false
    };
  },
  created() {
    this.flag = this.$route.path == "/home" ? false : true;
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    }
  },
  watch: {
    "$route.path": function(newVal) {
      console.log(this);
      if (newVal == "/home") {
        this.flag = false;
        this.active = 0;
      } else if (newVal == "/member") {
        this.flag = false;
        this.active = 1;
      } else if (newVal == "/shopcar") {
        this.flag = false;
        this.active = 2;
      } else if (newVal == "/search") {
        this.flag = false;
        this.active = 3;
      } else {
        this.flag = true;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.app-container {
  padding-top: 40px;
  padding-bottom: 50px;
  overflow-x: hidden;
}
.container-enter {
  opacity: 0;
  transform: translateX(100%);
}
.container-leave-to {
  opacity: 0;
  transform: translateX(-100%);
  position: absolute;
}
.container-enter-active,
.container-leave-active {
  transition: all 0.5s ease;
}
</style>
